<?php namespace App\Exceptions;

use Exception;

class SecurityException extends Exception
{
    const LoginFirst = 0x01;
    const NoPermission = 0x02;
    const Wait60Seconds = 0x03;
    const VerifyCodeNotMatch = 0x04;
    const PasswordNotMatch = 0x05;
    const VerifyCodeNotFound = 0x06;
    const CallOnOverDue = 0x07;
    const LowUserRights = 0x08;
    const IllegalMail = 0x09;
    const IllegalPhone = 0x10;
    const NoPermissionInOrder = 0x11;
    const NetWorkError = 0x12;
    const OverduePayKey = 0x0a;
    const OverDueActive = 0x0b;

    public function __construct($code = 0, array $data = [], Exception $previous = null)
    {
        switch ($code) {
            case self::LoginFirst:
                $message = trans('请先登录！');
                break;
            case self::NoPermission:
                $message = trans('不允许访问！');
                break;
            case self::Wait60Seconds:
                $message = trans('请等待60s后再获取');
                break;
            case self::VerifyCodeNotMatch:
                $message = trans('验证码不匹配');
                break;
            case self::PasswordNotMatch:
                $message = trans('密码不匹配');
                break;
            case self::VerifyCodeNotFound:
                $message = trans('未发送验证码');
                break;
            case self::LowUserRights:
                $message = trans('用户权限不足');
                break;
            case self::CallOnOverDue:
                $message = trans('已过期');
                break;
            case self::IllegalMail:
                $message = trans('非法邮箱');
                break;
            case self::IllegalPhone:
                $message = trans('非法手机号');
                break;
            case self::NoPermissionInOrder:
                $message = trans('没有操作此订单权限');
                break;
            case self::NetWorkError:
                $message = trans('网络错误');
                break;
            case self::OverduePayKey:
                $message = trans('支付码已过期');
                break;
            case self::OverDueActive:
                $message = trans('活动已结束');
                break;

            default:
                $message = trans('未知错误');
                break;
        }
        parent::__construct($message, $code, $previous);
    }
}